#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,M=1e6+10,K=1e6,INF=0x3f3f3f3f;
int n,m,tot,TOT,mxl,mxv,b[M],ans,bns;
struct node{int l,r;}a[N],c[N],d[N];
bool cmp(node a,node b){return a.l>b.l;}
void solve(){
    cin>>n>>m>>mxl>>mxv;
    for (int i=1;i<=n;i++){
        int d,v,k;
        cin>>d>>v>>k;
        if (k==0){
            if (v>mxv)
                a[i].l=d,
                a[i].r=mxl;
            if (v<=mxv)
                a[i].l=1,
                a[i].r=0;
        }
        if (k>0){
            if (v>mxv)
                a[i].l=d,
                a[i].r=mxl;
            if (v<=mxv){
                a[i].l=(mxv*mxv-v*v)/(2*k)+d+1,
                a[i].r=mxl;
                if (a[i].l>mxl) a[i].l=1,a[i].r=0;
            }
        }
        if (k<0){
            if (v>mxv)
                a[i].l=d,
                a[i].r=min(mxl,(v*v-mxv*mxv-2*k-1)/(-2*k)+d-1);
            if (v<=mxv)
                a[i].l=1,
                a[i].r=0;
        }
        //cout<<a[i].l<<' '<<a[i].r<<'\n';
    }
    memset(b,0,sizeof(b));
    for (int i=1;i<=m;i++){
        int x;
        cin>>x;
        b[x]=x;
    }
    tot=0;
    ans=0;
    b[K+1]=INF;
    for (int i=K;i>=0;i--)
        if (!b[i])
            b[i]=b[i+1];
    for (int i=1;i<=n;i++)
        if (b[a[i].l]<=a[i].r)
            ans++,
            c[++tot]=a[i];
    cout<<ans<<' ';
    sort(c+1,c+tot+1,cmp);
    TOT=0;
    for (int i=1,j=INF;i<=tot;i++)
        if (c[i].r<j) d[++TOT]=c[i],j=c[i].r;
    bns=0;
    for (int i=1,cur=INF;i<=TOT;i++)
        if (cur>d[i].r)
            cur=b[d[i].l],
            bns++;
    cout<<m-bns;
    cout<<'\n';
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;cin>>T;
    while (T--) solve();
    return 0;
}
